﻿using UnityEngine;
using System.Collections;

public class Controller : MonoBehaviour 
{
	public MachineGun[] m_machineGun;
	public Camera m_camera;
	
	// Update is called once per frame
	void Update () 
	{
		int i;

        if (Input.GetMouseButton(0))
        {
			Vector2 destPos = m_camera.ScreenToWorldPoint(Input.mousePosition);

			for( i = 0; i < m_machineGun.Length; i++ )
			{
				Vector2 srcPos = m_machineGun[i].transform.position;
				Vector2 shootDir = destPos - srcPos;
				
				shootDir.Normalize();
				
				m_machineGun[i].Shoot();
				m_machineGun[i].AimTo(shootDir);
			}
        }
        else
        {
			for( i = 0; i < m_machineGun.Length; i++ )
			{
				m_machineGun[i].StopShoot();
			}
        }
	}

}
